<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Proxy Test</title>
</head>
<body>
    <h1>Proxy Test Page</h1>
    <div id="result"></div>
    
    <script>
        // 测试API代理
        async function testProxy() {
            try {
                // 使用/api前缀测试代理
                const response = await fetch('/api/ai/', {
                    method: 'GET',
                    credentials: 'include'
                });
                
                if (response.ok) {
                    const data = await response.json();
                    document.getElementById('result').innerHTML = 
                        '<p style="color: green;">Proxy test successful!</p>' +
                        '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
                } else {
                    document.getElementById('result').innerHTML = 
                        '<p style="color: red;">Proxy test failed with status: ' + response.status + '</p>';
                }
            } catch (error) {
                document.getElementById('result').innerHTML = 
                    '<p style="color: red;">Error: ' + error.message + '</p>';
            }
        }
        
        // 测试直接访问前端路由
        function testFrontendRoute() {
            console.log('Opening frontend AI route...');
            window.open('/ai', '_blank');
        }
        
        // 运行测试
        testProxy();
    </script>
    
    <button onclick="testFrontendRoute()">Test Frontend AI Route</button>
</body>
</html>